package com.sense.kukoo.biz_media.model

import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.repo.bean.ResultBean
import com.sense.kukoo.common.repo.http.KukooHttpApi
import com.sense.kukoo.common.repo.http.KukooHttpManager
import com.sense.kukoo.common.repo.http.bean.CommentRecordBean
import com.sense.kukoo.common.repo.http.bean.ContentInfoBean
import com.sense.kukoo.common.repo.http.bean.ContentListeningBean
import okhttp3.RequestBody

class MediaDescriptionModel: BaseMvvmModel() {

    private val TAG: String = javaClass.simpleName

    override fun onModelCleared() {}

    suspend fun contentInfo(id: Long): ResultBean<ContentInfoBean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .contentInfo("${id}")
    }

    suspend fun contentListening(contentId: Long): ResultBean<ContentListeningBean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .contentListening("${contentId}")
    }

    suspend fun subscription(
        userId: Long
    ): ResultBean<Boolean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .subscription("${userId}")
    }

    suspend fun like(contentId: Long, contentUserId: Long): ResultBean<Boolean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .like("${contentId}", "${contentUserId}")
    }

    suspend fun commentSave(
        contentId: Long,
        contentUserId: Long,
        content: String,
        parentId: Long,
        replyUserId: Long,
    ): ResultBean<CommentRecordBean> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("contentId", contentId)
        hashMap.put("content", content)
        hashMap.put("contentUserId", contentUserId)
        hashMap.put("parentId", parentId)
        hashMap.put("replyUserId", replyUserId)
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .commentSave(mRequestBody)
    }

    suspend fun shareSuccess(
        id: Long,
    ): ResultBean<Boolean> {

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .shareSuccess("${id}")
    }
}